package servlet;

import java.sql.SQLException;
import java.util.List;
import java.util.TimerTask;

import server.GetRadomValue;
import service.tHistoryService;
import service.impl.tHistoryServiceImpl;
import util.DBUtils;
import entity.tDevice;

public class MyTask extends TimerTask
{
    
    public MyTask()
    {
        super();
    }
    
    public void run()
    {
        
        DBUtils db = new DBUtils();
        List<tDevice> devices;
        try
        {
            devices = db.getAllDevice();
            for (tDevice device : devices)
            {
                if (device.getMac() != null)
                {
                    tHistoryService ths = new tHistoryServiceImpl();
                    String[] date = GetRadomValue.getInstance().getArrayListValue(device.getMac());
                    if (date != null)
                    {
                        ths.add(0, date[0], device.getDeviceId());
                        ths.add(1, date[1], device.getDeviceId());
                        ths.add(2, date[2], device.getDeviceId());
                        ths.add(3, date[3], device.getDeviceId());
                    }
                }
            }
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        
    }
    
}